package com.fire.eyes.controller;

import com.fire.core.util.AjaxResult;
import com.fire.eyes.model.MyBuildingDetailResp;
import com.fire.eyes.model.MyMessageResp;
import com.fire.eyes.service.MyManagementService.ManagementService;
import com.fire.eyes.validation.GetMybuildingDetailDTO;
import com.fire.eyes.validation.GetMybuildingListDTO;
import com.fire.eyes.validation.TokenDTO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yangxiaotian
 * @version 1.0
 * @date 2019/1/18 17:40
 * @description:
 */
@Controller
public class MyManagementController {
    private final static Logger blogin = Logger.getLogger(MyManagementController.class);
    @Autowired
    private ManagementService managementService;

    /**
     * @author yangxiaotian
     * @date ${DATE} ${TIME}
     * @description:我都消息接口
     */
    @PostMapping(value = "/mymessages")
    @ResponseBody
    public AjaxResult myMessages(@RequestBody @Validated TokenDTO tokenDTO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            for (FieldError fieldError : bindingResult.getFieldErrors()) {
                System.out.println(fieldError.getDefaultMessage());
            }
        }
        AjaxResult result = new AjaxResult();
        MyMessageResp resp = new MyMessageResp();
        resp.setContent("你都消息");
        resp.setNumber("4");
        resp.setType("2");
        resp.setWho("小天");
        result.setContext(resp);
        result.setStatus("0");
        result.setMessage("获取我都消息成功");
        result.setTips("获取我都消息成功");
        return result;
    }

    /**
     * @author yangxiaotian
     * @date ${DATE} ${TIME}
     * @description:我都建筑物
     */
    @PostMapping(value = "/mybuildinglist")
    @ResponseBody
    public AjaxResult getMybuildingList(@RequestBody @Validated TokenDTO tokenDTO, BindingResult bindingResult) {
        AjaxResult result = new AjaxResult();
        if (bindingResult.hasErrors()) {
            for (FieldError fieldError : bindingResult.getFieldErrors()) {
                System.out.println(fieldError.getDefaultMessage());
            }
        }
        result = managementService.myBuildingList(tokenDTO);
        return result;
    }


    @PostMapping(value = "/mybuildingdetails")
    @ResponseBody
    public AjaxResult getbuildingDetails(@RequestBody @Validated GetMybuildingDetailDTO getMybuildingDetailDTO, BindingResult bindingResult) {
        AjaxResult result = new AjaxResult();
        if (bindingResult.hasErrors()) {
            for (FieldError fieldError : bindingResult.getFieldErrors()) {
                System.out.println(fieldError.getDefaultMessage());
            }
        }
        result=managementService.buildingDetails(getMybuildingDetailDTO);
        return result;
    }
}
